package system.communication;

import system.ui.Gui;
/**
 * This class polls the ConcreteMonitor.getHandControlMessage() method while
 * a handControlOn is hit.  This class is intended for the B requirement of the
 * train system project; and as such, is unfinished code.
 *
 * @author Elliot Cash
 * @version Cycle 1 - complete
 */
public class HandControlPoller extends Thread
{
    public boolean handControlOn = false;

    /**
     * Constructor for Objects of class HandControlPoller.
     */
    public HandControlPoller()
    {
    }

    /**
     * Starts the HandControlPoller thread running, so that it can send
     * queries to the system Hand Controls.
     */
    @Override
    public void run()
    {
        handControlOn = true; //the Hand Control must be on
        while(handControlOn)
        {
            //there are two Hand Controls; the switch cases give feedback
            //based on which combination is occurring; HC1 is on, HC2 is on,
            //both are on, or both are off (case 0)
            switch(Gui.whichHandControl)
            {
                case 1: //HC1 is on
                    ConcreteMonitor.getInstance().getHandControlStatus(1);
                    break;
                case 2: //HC2 is on
                    ConcreteMonitor.getInstance().getHandControlStatus(2);
                    break;
                case 3: //both Hand Controls are on
                    ConcreteMonitor.getInstance().getHandControlStatus(1);
                    ConcreteMonitor.getInstance().getHandControlStatus(2);
                    break;
                default:
                    break;
            }
            try
            {
                //the HC's are not polled as often as other messages
                Thread.sleep(100);
            }
            catch (InterruptedException ex)
            {
                System.err.println(ex.getMessage());
            }
        }
    }

    /**
     * Ends the polling process.
     */
    public void end()
    {
        handControlOn = false;
    }
}